// import { http } from '../common/http.js'
// module.exports = {
// 	loadLogin(options) {
// 		return http({
// 			url: '/auth/login',
// 			data: options,
// 			method: 'POST'
// 		})
// 	},
// 	getUserInformation(options) {
// 		return http({
// 			url: '/system/user/getUserById',
// 			data: options,
// 			method: 'GET'
// 		})
// 	}
// }
import {post ,get, ysHttp} from '../common/http.js'
import QS from 'qs';
const module = uni.requireNativePlugin('uniplugin_module-release')

//appKey和secret获取accessToken
export const getysToken = data =>{
	return ysHttp({
		method: "POST",
		url: "/lapp/token/get",
		headers: {
			'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8',
		},
		data:QS.stringify(data)
	})
}
//抓取图片
export const getysImage = data =>{
	return ysHttp({
		method: "POST",
		url: "/lapp/device/capture",
		headers: {
			'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8',
		},
		data:QS.stringify(data)
	})
}


//设备状态上报
export const getState = (data, isjson) => post('/sc/device/heartbeat', data, isjson)

//用户登录
export const loadLogin = data => post('/sc/auth/login', data)

//退出登录
export const loadLogout = data => post('/sc/auth/logout', data)

//查询当前库存
export const getInventory = params => get('/sc/inventory/current',params)

//查询历史操作记录
export const getHistorical = params => get('/sc/inventory/oper_log',params)

//库存操作
export const inventoryOperation = (data,isjson) => post('/sc/inventory/user_oper',data,isjson)

//库存异常上报
export const abnormalStock = (data,isjson) => post('/sc/inventory/error',data,isjson)

//智能柜基础信息
export const getCabinet = params => get('/sc/device',params)

//授权人员列表
export const getAuthorize = params => get('/sc/user/list',params)

//新增主柜
export const addMasterCabinet = data => post('/sc/device/main/add',data)

//修改主柜
export const setMasterCabinet = data => post('/sc/device/main/edit',data)

//删除主柜
export const delMasterCabinet = data => post('/sc/device/main/delete',data)

//新增副柜
export const addDeputyCabinet = (data,isjson)  => post('/sc/device/sub/add',data,isjson)

//修改副柜
export const setDeputyCabinet = data => post('/sc/device/sub/edit',data)

//删除副柜
export const delDeputyCabinet = data => post('/sc/device/sub/delete',data)

//通过条码查询货物信息
export const getPlasticGoods = params => get('/sc/inventory/barcode',params)

//统计：耗材消耗
export const getStatsConsume = params => get('/sc/stats/item/consume',params)

//统计：价格消耗
export const getStatsPrice = params => get('/sc/stats/price/consume',params)

//统计：耗材平均存储时间
export const getStatsTime = params => get('/sc/stats/item/avg_store_time',params)

//统计：分账号领用统计
export const getStatsTake = params => get('/sc/stats/user/take',params)

//获取USB设备列表
export const getDeviceList =function(usb_type){
	return new Promise(function(resolve,reject){
		module.getDeviceList((ret) => {
			console.log('USB设备列表信息',ret)
			let data=[]
			if(usb_type=="card"){
				ret.data.forEach(function(item,index){
					if(item.vendorId==65535){
						item.name="card-"+item.deviceId
						data.push(item)
					}
				})
			}else if(usb_type=="scan"){
				ret.data.forEach(function(item,index){
					if(item.vendorId==1409){
						item.name="scan-"+item.deviceId
						data.push(item)
					}
				})
			}
			resolve(data)
		})
	})
}
//16进制转十进制
export const switch16 =function(t){
	switch (t) {
	    case '1E':
	        return 1
	        break;
	    case '1F':
	        return 2
	        break;
	    case '20':
	        return 3
	        break;
	    case '21':
	        return 4
	        break;
	    case '22':
	        return 5
	        break;
	    case '23':
	        return 6
	        break;
	    case '24':
	        return 7
	        break;
	    case '25':
	        return 8
	        break;
	    case '26':
	        return 9
	        break;
	    case '27':
	        return 0
	        break;
	    case '28':
	        return 'Return'
	        break;
	    default :
	        return 'Return'
	}
}